#include "scalelabel.h"
#include "models/command.h"

#include <QPainter>

ScaleLabel::ScaleLabel(QWidget *parent, Qt::WindowFlags f):
    QLabel(parent,f)
{
    // Set the background of the widget to be transparent
    setAttribute(Qt::WA_TranslucentBackground);
}

void ScaleLabel::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    QRect rc = rect();

    // Set background color and draw rounded rectangle
    painter.setBrush(QBrush(Qt::black));
    painter.setPen(Qt::NoPen);
    painter.drawRoundedRect(rc, 3, 3);

    // Set pen for lines
    ;
    painter.setPen(QPen(Qt::white,1));

    // Draw horizontal line
    int y = height() - 10;
    painter.drawLine(10, y, width() - 10, y);

    // Draw vertical lines
    painter.drawLine(10, y - 4, 10, y);
    painter.drawLine(width() - 10, y - 4, width() - 10, y);

    // Draw text
    QFont font("微软雅黑");
    font.setPixelSize(int(14*g_xScale));
    painter.setFont(font);
    painter.setPen(Qt::white);
    rc.setTop(int(4*g_xScale));
    painter.drawText(rc, Qt::AlignHCenter|Qt::AlignTop, text());
}
